﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;
using System.Configuration;

namespace BHair
{
    public partial class xuanzesp : Form
    {
        public xuanzesp()
        {
            InitializeComponent();
        }

        private void xuanzesp_Load(object sender, EventArgs e)
        {
            select();
        }
        public void select() 
        {
            string constr = ConfigurationManager.ConnectionStrings["BHair.Properties.Settings.BHairDBConnectionString"].ConnectionString;
            SqlConnection conn = new SqlConnection(constr);
            string sql1 = "SELECT [iid] as 商品编号,[iname] as 商品名称 ,[ifprice] as 进货单价,[iuprice] as 售价,[iamount] as 库存数量 FROM [BHairDB].[dbo].[items]";
            DataTable dt = new DataTable();
            try 
            {
                conn.Open();
                SqlDataAdapter sda = new SqlDataAdapter(sql1,conn);
                sda.Fill(dt);
                this.skinDataGridView1.DataSource = dt;
            }catch(Exception e)
            {
                MessageBox.Show(e.Message);
            }

        }

        private void button1_Click(object sender, EventArgs e)
        {
            insert();
            //chuanzhi.jhid = 1;
            this.Close();
        }
        //将datagirdview数据插入表中
        public void insert() 
        {
            string rkid = chuanzhi.jhid;
            //string jhtime=
            string constr = ConfigurationManager.ConnectionStrings["BHair.Properties.Settings.BHairDBConnectionString"].ConnectionString;
            SqlConnection conn = new SqlConnection(constr);
            conn.Open();
           //for (int i = 0; i < this.skinDataGridView1.SelectedRows.Count;i++ )
           //{
               int spid =Int32.Parse( this.skinDataGridView1.SelectedCells[0].Value.ToString());
                string spname1 = this.skinDataGridView1.SelectedCells[1].Value.ToString();
                decimal jhdj = decimal.Parse(this.skinDataGridView1.SelectedCells[2].Value.ToString());
                string sqlin = string.Format("INSERT INTO [BHairDB].[dbo].[jh]([djid], [spid], [spname], [spjhj], [spjhs], [spjhtime], [spgys], [spjsr], [spjhje],[spjhbz])"
                + "VALUES('{0}',{1},'{2}',{3},0,  '','', '',0,'' )", rkid, spid, spname1, jhdj);
                //string sqlup = "";
                SqlCommand comm = new SqlCommand(sqlin,conn);
               comm.ExecuteNonQuery();
              // MessageBox.Show("ok");
                
           // }
            conn.Close();

        }
        //修改商品的库存数
        public void updata() 
        {


        }
    }
}
